/// <reference types="vitest" />
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import printHttpServer from './vite-plugin/printHttpServerAfterHMR'
// import { compression } from 'vite-plugin-compression2'
// import { visualizer } from 'rollup-plugin-visualizer'

// https://vitejs.dev/config/
export default ({ mode }) => {
  return defineConfig({
    plugins: [
      /* compression({
        algorithm: 'brotliCompress'
      }), */
      vue(),
      printHttpServer()
      // visualizer({ open: false })
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
        'vue-i18n': 'vue-i18n/dist/vue-i18n.mjs'
      }
    },
    server: {
      open: true,
      host: true
    },
    esbuild: {
      jsxFactory: 'h',
      jsxFragment: 'Fragment',
      jsxInject: 'import { h } from "vue";',
      drop: mode === 'development' ? [] : ['console', 'debugger']
    },
    build: {
      chunkSizeWarningLimit: 1500,
      rollupOptions: {
        output: {
          chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称
          entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称
          assetFileNames: '[ext]/[name]-[hash].[ext]', // 资源文件像 字体，图片等
          manualChunks: {
            'naive-ui': ['naive-ui'],
            three: ['three']
          }
        }
      }
    },
    test: {
      reporters: ['verbose', 'html', 'json'],
      outputFile: {
        json: './test/json-report.json',
        html: './test/index.html'
      }
    }
  })
}
